<?php
$cs = Yii::app()->getClientScript();
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_find_1.css');
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_list.css');
$findText = ''; //清空$findText
$screen = Blyn::app()->getUIManager()->getCurrentScreen();
$wxControl = $screen->getChildControl('BUIWXControl_1');
$eventList = Blyn::app()->getActiveApp()->getEventList();
$venderList = Blyn::app()->getActiveApp()->findVenderListByEventType();
$courtTypeList = Blyn::app()->getActiveApp()->getCourtTypeList();
unset($courtTypeList['badminton_court']);
    if(isset($nowCity)) {
        $city = $nowCity;//通常是省市拼音，如：china.chongqing
    }else {
        $attribute = Blyn::app()->getCurrentUser()->getAttribute('myCity_app' . Blyn::app()->getActiveApp()->getId());
        // if(isset($attribute))
        // {
        //   $city = $attribute->getValue();
        // }
        // else {
            $city='china.chongqing';
        // }
    }
$treeTable = new BTreeTable('BWInputValue');
$itemData = array(
    'city' => $city,
    'bookingStatus' => 'available',
    //下面的两个条件非常重要：
    'bookingStartTime' => '<='.time(),
    'bookingEndTime' => '>='.time(),
    //only get item for current space
    'spaceId'=>  Blyn::app()->getActiveSpace()->getId()
);
$app = Blyn::app()->getActiveApp();
$venderCourtTypeBookableList = array();

if (isset($_GET["openid"])) {
     $jq_openid=$_GET["openid"];
     $user = blyn::app()->getCurrentUser();
     $user->addContextVariable('jq_openid',$jq_openid);
}
?>

<meta name="viewport" contdent="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1" media="(device-height: 568px)">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="full-screen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<script>
//$("document").ready(function() {
//    $(".booking_list > dd").click(function() {
//        $(this).css("backgroundColor","rgb(243, 243, 246)");
//        $(this).siblings().css("backgroundColor","white");
//    });
//}); 
</script>
<body id="index">

    <header class="navbar">
        <div class="nav-wrap-left">
            <?php
            $bookingFindUrl = $wxControl->getLinkUrl(array(
                'name' => 'booking_find_1',
                'id' => 'booking_find_1'),array(
                'nowCity' => $city,   //$city=重庆
                'findType' => 'full' 
            ));
            ?>
            <a class="react brand" href="<?php echo $bookingFindUrl;?>">
                <span class="logo">
                    <font style="font-size:20px; font-family: Microsoft YaHei;">场地预订</font>
                </span>
            </a>
            <?php 
            $changeCityUrl = $wxControl->getLinkUrl(array(
                            'name' => '修改城市',
                            'id' => 'booking_change_city')
                    );
            ?>
            <span class="nav-city"><a gaevent="imt/hd/cityBottom" href="<?php //echo $changeCityUrl;?>" class="react">
                <?php
                $cityList = Blyn::app()->getActiveApp()->getCityList();
                echo $cityList[$city];
                ?>
                <space></space>
                <i class="text-icon icon-downarrow"></i></a>
            </span>

<!--            <div >
                <?php // echo CHtml::beginForm() ?>
                <?php
                $screen = Blyn::app()->getUIManager()->getCurrentScreen();
                $cityList = Blyn::app()->getActiveApp()->getCityList();
                $model = new BDynamicFormModel();
                $model->addField('findText');
                $model->addField('userCity');
                //by default, set user city to ChongQing
                $model->userCity = 'china.chongqing';

                $savedUserCity = Blyn::app()->getCurrentUser()->getAttribute('myCity_app' . Blyn::app()->getActiveApp()->getId());
                if ($savedUserCity instanceof BAttribute) {
                    $model->userCity = Blyn::app()->getCurrentUser()->getAttribute('myCity_app' . Blyn::app()->getActiveApp()->getId())->getValue();
                }

                if ($_POST != NULL && isset($_POST['BDynamicFormModel'])) {
                    $model->attributes = $_POST['BDynamicFormModel'];
                }

                if (!$savedUserCity instanceof BAttribute || $savedUserCity->getValue() != $model->userCity) {
                    Blyn::app()->getCurrentUser()->addAttribute('myCity_app' . Blyn::app()->getActiveApp()->getId(), $model->userCity);
                }
                ?>
                <div >
                    <div >
                        <?php // echo CHtml::activeDropDownList($model, 'userCity', $cityList, array('class' => 'span2')); ?>
                    </div>
                </div>
             
                <?php // echo CHtml::endForm() ?>
            </div>     -->
     </div>
        
        <!--刷新按钮-->
        <a class="refresh" href="<?php echo $bookingFindUrl;?>">
            <img src="<?php echo Yii::app()->request->baseUrl.'/images/mobile/refresh.png';?>" width="20" height="20"/>
        </a>
        <div id="ajax-loaderdiv" style="position: fixed;top: 0;left: 0;width: 100%;height: 100%;z-index: 35000;background-color: rgba(0, 0, 0, 0.3);display: none;">
            <img src="/billyn-dev/images/ajax-loader.gif" class="ajax-loader"style="position: absolute;left: 50%;top: 50%;margin-left: -16px;margin-top: -16px;display: block;"/>
        </div>
        <script>
        $(".refresh").click(function() {
            $("#ajax-loaderdiv").show();
        });
        function goRecommend(elem,link) {
            elem.style.backgroundColor = "rgb(243, 243, 246)";
            location.href = link;
        }
        </script>
        <?php
        $wxControl->renderView('booking_navigation',array());?>
    </header>
    
    <!--haobing's code start-->
    <style type="text/css">
	body{margin:0px;}
	#header{height:40px;width:100%;background-color: #2BB2A3;font-size: 20px;float: left;font-family: 微软雅黑;color:white;padding-left: 5px;}
	#header span{display:inline-block;}
	#header a {display: inline-block;margin-top: 1px;float: right;}
	#body1{height:170px;width:100%;background: url(<?php echo Yii::app()->request->baseUrl.'/images/BWeSport/background.jpg'?>) no-repeat;background-size: 100% 100%;text-align: center;}
	.main{width: 350px;height: 100px;background-color: white;padding-top: 8px;}
	.tu{width:96px;height: 74px;float: left;margin-left: 8px;}
	.wen{width: 200px;float: left;margin-left: 10px;}
        .wen p {line-height: 28px;}
	#imgGo {overflow: hidden; position: relative;  padding: 0;margin: 0 auto;}
	#imgGo ul {overflow: hidden; position: absolute; top: 0; left: 0; margin: 0; padding: 0;}
	#imgGo ul li {overflow: hidden; float: left; margin: 0; padding: 0;}
	#imgIndex {overflow: hidden; position: absolute; bottom: 0; margin: 0; padding-right:50%; width: 100%; height: 12%; text-align: center;}
	#imgIndex span {display: inline-block; width: 10px; height: 10px; margin-right: 3%; border-radius: 100%; background-color: #BDBDBD;cursor: pointer; opacity: 0.4;}

	.shadow{height: 60px;width: 290px;background-color: black;border-radius: 5px;opacity:0.45;}
	.img{position:absolute;top: 180px;left: 50%;margin-left:-146px;}
  	img.s{border:0;height: 100px;width:100%;}
  	img.l{border:0;height: 60px;width:60px;display:inline-block;margin-bottom:10px;}
  	.court_type_list td{height: 100px;background-color: #F0EFED;padding: 0;}
  	button{border:0;padding: 0;}
  	p{line-height: 1.2em;}
    </style>
	<div id="body1">
            <!--<div class="shadow img">
            </div>
            <div style="width: 280px;margin: 0 auto;padding-top: 135px;z-index:1000;">
                <form>
                    <input type="text" style="height:24px;width:220px;position: relative;border: 1px solid #dedede;">
                    <input type="image" src="<?php //echo Yii::app()->request->baseUrl.'/images/BWeSport/search.jpg'?>" style="position: relative;top: 9px;left: -4px;" />
                </form>	
            </div>-->
	</div>
	<br>
	<?php $control->renderView('booking_find_slide_1'); ?>
	<!--imgGo.js加载到id=imgGo的div后面-->
	<script src="<?php echo Yii::app()->request->baseUrl.'/js/mobile/imgGo.js';?>" type="text/javascript"></script>
	
	<div style=" width:100%; text-align:center;padding:0;padding-top: 10px;">   
            <hr style=" width:35%; display:inline-block;border-color:#AAAAAB;" > <p style="width:82px;text-align:center;position:relative;bottom:15px;display:inline-block;color:#3EB8A8;font-family:微软雅黑;font-weight:bold">&nbsp&nbsp&nbsp运动类型&nbsp&nbsp&nbsp</p>
            <hr style=" width:35%;display:inline-block;border-color:#AAAAAB;" >
        </div>
             <?php 
                $courtTypeIcons = array(
                    'soccer_court_5' => Yii::app()->request->baseUrl . '/images/BWeSport/5.png',
                    'soccer_court_7' => Yii::app()->request->baseUrl . '/images/BWeSport/7.png',
                    'soccer_court_11' => Yii::app()->request->baseUrl . '/images/BWeSport/11.png',
                );
                $courtforName = array(
                    'soccer_court_5' => '五人足球场',
                    'soccer_court_7' => '七人足球场',
                    'soccer_court_11' => '十一人足球场',
                );
                if(isset($findContext)) {
                    $findText = '';
//                    $app->findByFindText($findText, $findContext);
                }
            ?>
	<div><table class="court_type_list" style="width:100%;border:0;padding-left:40px;text-align:center;">
	<tr>	
            <?php  
            $valueList = $treeTable->getValueList('courtType', array('itemData' => $itemData));
            foreach ($courtTypeList as $courtType => $courtName) {  
                $findText = 'city=' . $city . ' courtType=' . $courtType;
                $flagText = $courtName;
                $count = isset($valueList[$courtType]) ? $valueList[$courtType] : 0;
                $typeUrl = $wxControl->getLinkUrl(array(
                    'name' => $courtName,
                    'id' => 'booking_list'), array(
                    'listPage' => 'booking_list_by_day',
                    'findText' => $findText,
                    'flagText' => $flagText,
                    'nowCity' => $city  //通常是省市拼音，如：china.chongqing
                ));?>
            <td>
                <a href="<?php echo $typeUrl;?>">
                    <div style="padding: 10px 0;height:80px;width:110px;margin:0 auto;background-color:white;border-radius: 5px"><img class="l" src="<?php echo $courtTypeIcons[$courtType] ?>">
                        <p style="text-align: center;color: black;"><?php echo $courtforName[$courtType] ?></p>
                    </div>
                </a>
            </td>
            <?php }?>
	</tr>
	</table></div>

	<div style=" width:100%; text-align:center;padding:0;padding-top: 10px;"> 
            <hr style=" width:35%; display:inline-block;border-color:#AAAAAB;" > <p style="width:82px;text-align:center;position:relative;bottom:15px;display:inline-block;color:#3EB8A8;font-family:微软雅黑;font-weight:bold">&nbsp&nbsp&nbsp场馆&nbsp&nbsp&nbsp</p>
            <hr style=" width:35%; display:inline-block;border-color:#AAAAAB;" >
            </div>
            <div>
         <table style="border:0;padding-left:50px;width:100%;text-align:center;">
             <tr>
                <?php
                $count3=0;
                $count3=(integer)$count3;
                $allcount=count($eventList);
                foreach($eventList as $event) {
                    $eventId = $event->getId();
                    $eventName = $event->getName();
                    $vender = $event->getMessageManager()->getMessage('vender');
                    $vendeImage = $vender->getMediaManager()->getMedia('image')->getContent();//场馆图片
                    $venderName = $vender->getMediaManager()->getMedia('venderName')->content;//场馆名称
                    $findText = 'city=' . $city . ' eventId=' . $eventId;
                    $flagText = $courtName;
                    $gymUrl = $wxControl->getLinkUrl(array(
                        'name' => $venderName,
                        'id' => 'booking_list'), array(
                        'listPage' => 'booking_list_by_timeSlot',
                        'findText' => $findText,
                        'flagText' => $flagText,
                        'nowCity' => $city  //通常是省市拼音，如：china.chongqing
                    ));?>
                    <td>
                        <div style="background-color:white;margin: 0 auto;height:85px;width: 135px;padding-top: 8px;border-radius:3px;">
                            <a href="<?php echo $gymUrl;?>">
                                <img src="<?php echo Yii::app()->request->baseUrl . $vendeImage ?>"  style="margin-bottom: 8px;width:118px;height:60px">
                                <p style="text-align:center;font-size:12px;color:black;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;"><?php echo $venderName;?></p>
                            </a>
                        </div>
                    </td>
                    <?php
                    $count3++;
                    if($count3%2==0)
                    {
                        echo "</tr>";
                    }
                    if($count3%2==0 && $count3!=$allcount)
                    {
                       echo "<tr>";
                    }
                    if($count3==$allcount && $count3%2!=0)
                    {
                        echo '</tr>';
                    }    
                }?>
                </table>
            </div>
    <?php //$control->renderView('booking_find_recommend',array('itemData'=>$itemData,'courtTypeList'=>$courtTypeList)); ?>
    <footer>
        <div class="footer-copyright">
            <div class="hr"></div>
            <span class="footer-copyright-text">
                Copyright © 2014 billyn.net </span>
        </div>
    </footer>
